package idea.think.adapter;

import idea.think.IdeaAll;
import idea.think.R;
import idea.think.vo.Data;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

public class CustomAdapter extends ArrayAdapter<Data> {
	public ArrayList<Integer> alist = new ArrayList<Integer>(); //Checkbox 담는 리스트
	IdeaAll iAll;
	
	public CustomAdapter(Context context, List<Data> objects) {
		super(context, 0, objects);
		iAll = (IdeaAll)context;
	}		
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v;
		final ViewHolder holder;			
		LayoutInflater inflater = iAll.getLayoutInflater();
		
		if(convertView == null){
			v = inflater.inflate(R.layout.cate_dialog, null);
			holder = new ViewHolder();
			holder.cateText = (TextView) v.findViewById(R.id.categoryText);
			holder.cateCheck = (CheckBox) v.findViewById(R.id.categoryCheck);			
			v.setTag(holder);				
		}else{
			v = convertView;
			holder = (ViewHolder)v.getTag();
		}
		
		final Data data = getItem(position);
		holder.cateText.setText(data.getCateText());
		Cursor cursor = iAll.selectCategory();
		cursor.moveToNext();			

		holder.cateCheck.setTag(String.valueOf(cursor.getInt(cursor.getColumnIndex("_id"))));
		holder.cateCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {			        
		        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {			      
		           if(holder.cateCheck.isChecked() == true){
		        	   Log.e("TA", "id = " + data.getCateCheck());
		        	   alist.add(data.getCateCheck());
		           }
		        }
		});
		
		return v;
	}
	
}
